package com.csii.mobilebanking.expandablelistview.util;

public class StringUtil {
	/***
	 * 屏蔽证件号码 idCard<=8 显示第一位和最后一位 idCard>8 显示前两位和最后后两位
	 * 
	 * @param idCard
	 * @return
	 */
	public static String screeningIdCard(String idCard) {
		int length = idCard.length();
		StringBuilder builder = new StringBuilder();
		// 屏蔽
		if (length <= 8) {
			int lastLength = length - 1;
			for (int i = 0; i < length; i++) {

				if (i == 0 || i == lastLength) {
					builder.append(idCard.charAt(i));
				} else {
					builder.append('*');
				}
			}
		} else {
			int lastLength = length - 2;
			for (int i = 0; i < length; i++) {

				if (i < 2 || i >= lastLength) {
					builder.append(idCard.charAt(i));
				} else {
					builder.append('*');
				}
			}
		}
		return builder.toString();
	}

	/***
	 * 屏蔽存折号码 显示后四位
	 * 
	 * @param passbookNumber
	 * @return
	 */
	public static String screeningPassbook(String passbookNumber) {
		int length = passbookNumber.length();
		StringBuilder builder = new StringBuilder();
		// 屏蔽

		int lastLength = length - 4;
		for (int i = 0; i < length; i++) {

			if (i>=lastLength) {
				builder.append(passbookNumber.charAt(i));
			} else {
				builder.append('*');
			}
		}
		return builder.toString();

	}
	

}
